;;;the key idea is that you're going to build the system in layers
;;;and set up abstraction barries that isolate the details at the lower layers
;;;from the thing that's going on at the upper layers
 
;(make-rat n d)
;(numer xxx) --> n
;(denom xxx) ---> d

;defining +rat without data abstraction

; (define (+rat x y)
;   (cons (+ (* (car x) (cdr y))
;            (* (car y) (cdr x)))
;         (* (cdr x) (cdr y))))
 
(define (+rat x y)
  (make-rat
   (+ (* (numer x) (denom y))
      (* (numer y) (denom x)))
   (* (denom x) (denom y))))
 
 
(define (*rat x y)
  (make-rat
   (* (numer x) (numer y))
   (* (denom x) (denom y))))

(define (make-rat n d)
  (cons n d))
 
(define (numer x) (car x))
(define (denom x) (cdr x))
 
(define a (make-rat 1 2))
(define b (make-rat 1 4))
(define ans (+rat a b))
; (ans)
(numer ans) 
(denom ans) 

; gcd is get a greatest common divisor

; (define (make-rat n d)
;   (let ((g (gcd n d)))
;     (cons (/ n g)
;           (/ d g))))
 
;;; data abstraction
;;; use                | +rat *rat -rat
;;; abstraction layer  | make-rat numer denom
;;; representation     | pairs
